home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SDL32.ASM < prev    next >
Assembly Source File  |  1988-08-16  |  25KB  |  1,003 lines

  1. page    80,132
  2. title    SDL 3.2 - Sorted Directory List
  3. sdl    segment
  4. sdlp    proc    far
  5.     assume    cs:sdl,ds:sdl,es:sdl
  6. ;
  7. ; SORTED DIRECTORY LIST 3.2
  8. ;
  9. ; SDL [d:][path][filename[.ext]][/options]
  10. ;
  11. ; Options:  General
  12. ;         E    erase screen
  13. ;         P    pause when screen full
  14. ;         W    4 column format (2 if width 40)
  15. ;        Sort options (sort on filename.ext is the default)
  16. ;         N    do not sort entries
  17. ;         S    sort by file size
  18. ;         D    sort by date and time
  19. ;         X    sort by file type (ext)
  20. ;        Sub-directories
  21. ;         T    list sub-directory names
  22. ;         F    use with T to list file names by directory
  23. ;         I    use with TF to indent file lists (not supported on
  24. ;            width 40 screens)
  25. ;         A    use with T to list all file names together
  26. ;
  27. ; Default:  *.* sorted by name.ext, 2 cols wide (1 on width 40 screen), no
  28. ;        screen erase or pause at end of page, using current directory.
  29. ;
  30. ; Notes:
  31. ;   1. Path specifications:
  32. ;      a. paths must end with \.
  33. ;      b. specifying a leading \ starts the path search at the root directory.
  34. ;      No leading \ will start the path at the current directory.
  35. ;      c. not specifying a path starts the operation at the current directory.
  36. ;   2. The space used by sub-directories is not accounted for.
  37. ;   3. Directory listings do not include the '.' or '..' entries.
  38. ;   4. The specified filename.ext may include ? and/or *.
  39. ;
  40. ; Output formats:  Width 80 - 2 or 4 columns   (option TFI - 1 or 2 columns)
  41. ;           Width 40 - 1 or 2 columns
  42. ;
  43. ; Filename in listing may be preceeded by one of the following char.:
  44. ;        r - read-only file
  45. ;        h - hidden file
  46. ;        s - system file
  47. ;        \ - sub-directory name
  48. ;   If a file has more than 1 attribute, only the last is shown.
  49. ;
  50. ; Written by W. C. Bodycomb
  51. ;        Version 1.0 - original version, runs under DOS 1.0 and 1.1
  52. ;        Version 2.0 - support for DOS 2.0, runs under DOS 1.0, 1.1, 2.0
  53. ;        Version 3.0 - support for paths and sub-directories, runs under
  54. ;              DOS 2.0.
  55. ;        Version 3.2 - Sort in descending order for date and file size 
  56. ;        options.  Make file extension ".*" by default.  Fix MASM 3 errors. 
  57. ;        Reversed test for 80 column display because some MS-DOS systems do 
  58. ;        not use the fixed address that PC-DOS does. Print the directory 
  59. ;        name instead of "<curr>". Ted Shapin, 11/21/85.
  60. ;
  61.     org    100h        ;set up for COM
  62. subp    proc    near
  63. ;
  64. ; get current or specified drive
  65. ;
  66. bgn:    call    clear        ;clear ctrs
  67.     cld            ;set direction
  68.     mov    si,offset init    ;init.
  69.     mov    di,offset dxfcb ;  the
  70.     mov    cx,19        ;    dummy
  71.     repz movsb        ;      FCB
  72.     mov    ah,19h        ;get
  73.     int    21h        ;  current
  74.     add    al,65        ;    disk
  75.     mov    si,offset path    ;      and
  76.     mov    [si],al     ;     save
  77.     mov    di,80h        ;get
  78.     mov    ch,0        ;  lth of
  79.     mov    cl,[di]     ;    of param
  80.     jcxz    vol1        ;br if no parms
  81.     inc    di        ;start of parms
  82.     mov    al,' '          ;scan off
  83.     repe scasb        ;  blanks
  84.     je    vol1        ;br if no parm
  85.     dec    di        ;adj
  86.     inc    cx        ;  values
  87.     cmp    cx,2        ;long enough
  88.     jb    vol1        ;br no
  89.     cmp    byte ptr [di]+1,':' ;is drive specified
  90.     jne    vol1        ;br no
  91.     mov    al,[di]     ;save
  92.     and    al,0dfh     ;  drive
  93.     mov    [si],al     ;    letter
  94.     inc    di        ;incr
  95.     inc    di        ;  adr
  96.     dec    cx        ;decr
  97.     dec    cx        ;  count
  98. ;
  99. ; get volume label
  100. ;
  101. vol1:    push    di        ;save
  102.     push    cx        ;  regs
  103.     mov    dx,offset da    ;set
  104.     mov    ah,1ah        ;  dta
  105.     int    21h        ;    adr
  106.     mov    al,[si]     ;put drive
  107.     mov    tia+9,al    ;  in header
  108.     sub    al,64        ;set
  109.     mov    byte ptr dfcb,al     ;  drive
  110.     mov    di,offset svvol ;save area
  111.     mov    ah,11h        ;set get first
  112.     mov    dx,offset dxfcb ;look for
  113.     int    21h        ;  vol label
  114.     or    al,al        ;any vol label
  115.     jnz    fpth        ;br no
  116.     mov    si,offset da+8    ;label adr
  117.     mov    cx,11        ;save
  118.     repz movsb        ;  label
  119. ;
  120. ; save specified path
  121. ;
  122. fpth:    mov    byte ptr [di],' ' ;mark end
  123.     pop    cx        ;restore
  124.     pop    di        ;  regs
  125.     jcxz    fopt1        ;br if no path/fnm
  126.     mov    dx,cx        ;save count
  127.     mov    bp,di        ;  and adr
  128.     add    di,cx        ;start
  129.     dec    di        ;  at
  130.     std            ;    end
  131.     mov    al,'\'          ;find end
  132.     repne scasb        ;  of path
  133.     cld            ;set direction
  134.     jne    fopt        ;br-not found
  135.     inc    cx        ;adj count
  136.     mov    si,bp        ;copy start adr
  137.     sub    dx,cx        ;save non-path lth
  138.     mov    di,offset path+2 ;move
  139.     repz movsb        ;  path
  140.     mov    fspca,di    ;save path end adr
  141.     mov    bp,si        ;set new start adr
  142. ;
  143. ; get options
  144. ;
  145. fopt:    mov    di,bp        ;get start adr
  146.     mov    cx,dx        ;  and lth
  147. fopt1:    jcxz    eopt        ;br-no options or filename
  148.     mov    al,'/'          ;find
  149.     repne scasb        ;  options
  150.     jne    gfspc        ;br-no options
  151.     dec    di        ;adj
  152.     inc    cx        ;  values
  153.     mov    si,di        ;copy adr
  154.     push    di        ;  and save
  155.     sub    dx,cx        ;save filespec size
  156. opt:    cmp    byte ptr [si],'/' ;is it /
  157.     je    opt3        ;keep looking
  158.     mov    al,byte ptr [si] ;get char
  159.     and    al,0dfh     ;force upper case
  160.     mov    di,offset swn    ;set adr
  161.     mov    bx,400h     ;  and flag
  162. opt1:    scasb            ;option found
  163.     je    opt2        ;br yes
  164.     shr    bx,1        ;check next
  165.     jnz    opt1        ;  option
  166.     jz    opt3        ;not valid option
  167. opt2:    or    word ptr sw,bx    ;set option
  168. opt3:    inc    si        ;check
  169.     loop    opt        ;  all char
  170.     pop    di        ;restore reg
  171. ;
  172. ; get specified filespec
  173. ;
  174. gfspc:    mov    byte ptr [di],' ' ;set delimiter
  175.     mov    cx,dx        ;get count
  176.     mov    si,bp        ;  and adr
  177.     jcxz    eopt        ;br-no filespec
  178.     cmp    byte ptr [si],' ' ;any filespec
  179.     je    eopt        ;br no
  180.     push    di        ;save end ptr
  181.     std    ;look for filename extension
  182.     mov    al,'.'        ;by scanning for
  183.     repne    scasb        ;a period
  184.     cld        ;reset to up
  185.     pop    di        ;restore pointer
  186.     je    gfspc2        ;we found one
  187.     mov    si,offset wild    ;point to ".*"
  188.     movsb        ;and move
  189.     movsb        ;it
  190.     mov    byte ptr [di],' ' ; add delimiter again
  191.     mov    si,bp        ;restore ptr to filespec
  192. gfspc2:    mov    di,offset dfcb    ;let DOS
  193.     mov    ax,2900h    ;  parse
  194.     int    21h        ;    filespec
  195. ;
  196. ; initialize options
  197. ;
  198. eopt:    mov    di,fspca    ;move dir.
  199.     call    mvfs        ;  filespec
  200.     test    byte ptr sw1,4        ;T option
  201.     jnz    eopt1        ;br yes
  202.     and    byte ptr sw1,0fch    ;clear A and F
  203. eopt1:    test    byte ptr sw1,1        ;A option
  204.     jz    eopt2        ;br no
  205.     and    byte ptr sw1,0fdh    ;clear F option
  206.     mov    cx,19        ;set count
  207.     mov    si,offset dirm    ;change
  208.     mov    di,offset h2+25 ;  hdrs
  209.     repz movsb        ;    to dir#
  210. eopt2:    test    byte ptr sw,8        ;wide
  211.     jz    eopt3        ;br no
  212.     mov    coln,4        ;set cols to 4
  213.     mov    si,offset h3    ;hdr adr
  214.     mov    di,offset h2+15 ;change
  215.     mov    cx,5        ;  bytes to
  216.     repz movsb        ;    sector
  217. eopt3:    push    ds        ;save data segment
  218.     mov    ax,40h        ;point to
  219.     mov    ds,ax        ;  data area
  220.     mov    ax,ds:4ah    ;get screen cols
  221.     pop    ds        ;restore data segment
  222.     cmp    ax,40        ;40 col
  223.     jne    eopt4        ;br no
  224.     or    byte ptr sw1,128     ;set 40 col
  225.     shr    coln,1        ;cols
  226.     jnz    fa        ;  /2
  227. eopt4:    test    byte ptr sw1,2        ;option F
  228.     jz    fa        ;br no
  229.     test    byte ptr sw,1        ;I option
  230.     jz    fa        ;br no
  231.     shr    coln,1        ;cols/2
  232.     mov    colp,40     ;set offset
  233. ;
  234. ; get FAT info
  235. ;
  236. fa:    mov    dl,path     ;get
  237.     sub    dl,64        ;  drive no
  238.     mov    ah,36h        ;get DOS 2
  239.     int    21h        ;  fat info
  240.     cmp    ax,0ffffh    ;br if
  241.     jne    fa1        ;  drive ok
  242.     int    20h        ;give up
  243. fa1:    mov    word ptr bpsc,cx     ;save bytes/sec
  244.     mov    ah,0        ;clear high byte
  245.     mov    word ptr scpf,ax     ;save sec/fat
  246.     xchg    cx,dx        ;find bytes per
  247.     mul    dx        ;  alloc. unit
  248.     mul    bx        ;free bytes
  249.     mov    word ptr free,ax     ;save low
  250.     mov    word ptr free+2,dx    ;  and high
  251. ;
  252. ; clear screen
  253. ;
  254. clr:    test    byte ptr sw,128        ;screen clear
  255.     jz    sdlh        ;br no
  256.     sub    cx,cx        ;col 0, row 0
  257.     mov    dx,184fh    ;last row, col
  258.     test    byte ptr sw1,128     ;80 cols
  259.     jz    clr1        ;br yes
  260.     mov    dx,1827h    ;set 40 col
  261. clr1:    mov    bh,7        ;color
  262.     mov    ax,600h     ;scroll
  263.     int    10h        ;  screen
  264.     sub    dx,dx        ;set
  265.     mov    ah,2        ;  cursor
  266.     mov    bh,0        ;    to
  267.     int    10h        ;      0
  268. ;
  269. ; print SDL header
  270. ;
  271. sdlh:    mov    dx,offset h1    ;print
  272.     call    prt        ;  header
  273.     mov    si,offset svvol ;label adr
  274. sdlh1:    lodsb            ;get char
  275.     cmp    al,' '          ;end of label
  276.     je    sdlh2        ;br yes
  277.     mov    dl,al        ;print
  278.     call    prtc        ;  char
  279.     jmp    sdlh1        ;next char
  280. sdlh2:    mov    ah,2ah        ;get
  281.     int    21h        ;  date
  282.     mov    si,offset mth    ;field start
  283.     mov    al,dh        ;convert
  284.     call    x2        ;  month
  285.     mov    al,dl        ;convert
  286.     call    x2        ;  day
  287.     mov    ax,cx        ;adjust
  288.     sub    ax,1900     ;  year
  289.     call    x2        ;convert year
  290.     mov    ah,2ch        ;get
  291.     int    21h        ;  time
  292.     mov    si,offset ti    ;field start
  293.     mov    al,ch        ;convert
  294.     call    x2        ;  hour
  295.     mov    al,cl        ;convert
  296.     call    x2        ;  minutes
  297.     mov    dx,offset h1evl ;print
  298.     call    prt        ;  hdr
  299.     test    byte ptr sw1,128     ;width 40
  300.     jz    sdlh3        ;br no
  301.     call    ckpg        ;print cr
  302. sdlh3:    mov    dx,offset h1a    ;print
  303.     call    prt        ;  hdr
  304.     mov    si,word ptr free     ;convert